/*
 * 版权所有(c)  1952110078@qq.com  2022 - 2022
 */

package com.ldc.commonlibs.utils;

import android.text.TextUtils;

import com.ldc.commonlibs.conatants.ParamsConstants;
import com.ldc.commonlibs.model.AccountModel;
import com.ldc.commonlibs.model.BindingsModel;
import com.ldc.commonlibs.model.ProfileModel;

import java.util.List;

/**
 * @author liudc
 * @since 2022/7/10 22:53
 */
public class DataSourceUtil {


    public static void putCookie(String value) {
        SpUtil.putString(ParamsConstants.COOKIE, value);
    }

    public static String getCookie() {
        return SpUtil.getString(ParamsConstants.COOKIE, "");
    }

    public static void putToken(String token) {
        SpUtil.putString(ParamsConstants.TOKEN, token);
    }

    public static String getToken() {
        return SpUtil.getString(ParamsConstants.TOKEN, "");
    }

    public static void putAccountData(String json) {
        if (TextUtils.isEmpty(json)) {
            return;
        }
        SpUtil.putString(ParamsConstants.ACCOUNT, json);
    }

    public static AccountModel getAccount() {
        final String json = SpUtil.getString(ParamsConstants.ACCOUNT, "");
        if (TextUtils.isEmpty(json)) {
            return null;
        }
        return JsonUtil.jsonToModel(json, AccountModel.class);
    }

    public static void putProfileData(String json) {
        if (TextUtils.isEmpty(json)) {
            return;
        }
        SpUtil.putString(ParamsConstants.PROFILE, json);
    }

    public static ProfileModel getProfile() {
        final String json = SpUtil.getString(ParamsConstants.PROFILE, "");
        if (TextUtils.isEmpty(json)) {
            return null;
        }
        return JsonUtil.jsonToModel(json, ProfileModel.class);
    }

    public static void putBindingsData(String json) {
        if (TextUtils.isEmpty(json)) {
            return;
        }
        SpUtil.putString(ParamsConstants.BINDINGS, json);
    }

    public static List<BindingsModel> getBindings() {
        final String json = SpUtil.getString(ParamsConstants.BINDINGS, "");
        if (TextUtils.isEmpty(json)) {
            return null;
        }
        return JsonUtil.jsonToModelByType(json, BindingsModel.class);
    }
}
